﻿@model  FineAdmin.Model.BlogPostsModel
@using FineAdmin.Model;
@{
    ViewBag.Title = Model.Title;
    var BlogCommentList = ViewBag.BlogCommentList as List<BlogCommentModel>;
}
@section styles{
    <style>
        .clicks {
            display: inline-flex;
            text-align: center;
        }

            .clicks span {
                margin-left: 6px;
                line-height: 24px;
            }

            .clicks i {
                line-height: 24px;
                margin-left: 6px;
            }
    </style>
}
<div class="content whisper-content leacots-content details-content">
    <div class="cont w1000">
        <div class="whisper-list">
            <div class="item-box">
                <div class="review-version">
                    <div class="form-box">
                        <div class="article-cont">
                            <div class="title ">
                                <h3>@Model.Title</h3>
                                <span class="clicks">
                                    <p class="cont-info"><span class="data">@Model.CreateTime.ToString("yyyy-MM-dd")</span><span class="types">@Model.CName</span></p>

                                    <i class="layui-icon layui-icon-praise"></i><span>@Model.Likes</span>
                                    <i class="layui-icon layui-icon-tread"></i><span>@Model.Trample</span>
                                    <i class="layui-icon layui-icon-fire"></i><span>@Model.Clicks</span>
                                </span>
                            </div>
                            @Html.Raw(Model.BlogContent)
                            <div class="btn-box">
                                @*<button class="layui-btn layui-btn-primary">上一篇</button>
                                    <button class="layui-btn layui-btn-primary">下一篇</button>*@
                                <button class="layui-btn layui-btn-primary" onclick="javascript:history.back(-1)">返回</button>
                            </div>
                        </div>
                        @if (ViewBag.EnableCommentSys == "1")
                        {
                            <div class="form">
                                <form class="layui-form" action="">
                                    <div class="layui-form-item layui-form-text">
                                        <div class="layui-input-block">
                                            <textarea name="desc" placeholder="既然来了，就说几句" class="layui-textarea" id="desc"></textarea>
                                        </div>
                                    </div>
                                    <div class="layui-form-item" style="text-align: right;">
                                        <div class="layui-inline">
                                            <input type="text" id="nickname" placeholder="昵称" class="layui-input" />
                                        </div>
                                        <div class="layui-inline">
                                            <img src="/Blog/GetSubmitCode" onclick="getcode()" id="codeimg" />
                                        </div>
                                        <div class="layui-inline">
                                            <input type="text" id="vcode" placeholder="验证码" class="layui-input" />
                                        </div>
                                        <div class="layui-inline">
                                            <button class="layui-btn definite" type="button">確定</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        }
                    </div>
                    @if (ViewBag.EnableCommentSys == "1")
                    {
                        <div class="volume" id="volume">
                            全部留言 <span>@ViewBag.Total</span>
                        </div>
                        <div class="list-cont">
                            @foreach (var item in BlogCommentList)
                            {
                                <div class="cont">
                                    <div class="img">
                                        <img src="../BlogStatic/img/header.png" alt="">
                                    </div>
                                    <div class="text">
                                        <p class="tit"><span class="name">@(string.IsNullOrWhiteSpace(item.NickName) ? "热心网友" : item.NickName)</span><span class="data">@item.CreateTime</span></p>
                                        <p class="ct">@Html.Raw(item.Contents)</p>
                                    </div>
                                </div>
                            }
                        </div>
                    }
                </div>
            </div>
        </div>
        @if (ViewBag.EnableCommentSys == "1")
        {
            <div id="demo" style="text-align: center;"></div>
        }
    </div>
</div>


@section scripts{
    <script>
        var Total = "@ViewBag.Total";
        var Page = "@ViewBag.Page";
        var PostsId = "@ViewBag.PostsId";
    </script>
    <script type="text/javascript">
        function getcode() {
            //$("#code").src = '/mobile/GetSubmitCode?' + Math.random()
            document.getElementById("codeimg").src = "/Blog/GetSubmitCode?r=" + Math.random();
        }

        layui.config({
            base: '../BlogStatic/js/util/'
        }).use(['element', 'laypage', 'form', 'menu', 'jquery'], function () {
            element = layui.element, laypage = layui.laypage, form = layui.form, menu = layui.menu, $ = layui.$;
            laypage.render({
                elem: 'demo'
                , curr: Page
                , count: Total //数据总数，从服务端得到
                , jump: function (obj, first) {
                    //obj包含了当前分页的所有参数，比如：
                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    console.log(obj.limit); //得到每页显示的条数

                    //首次不执行
                    if (!first) {
                        //do something
                        window.location.href = "/Blog/BlogDetail?Id=" + PostsId + "&p=" + obj.curr + "#volume";
                    }
                }
            });

            menu.init();


            $('.definite').on('click', function (e) {

                var nickname = $("#nickname").val();
                var captcha = $("#vcode").val();
                var desc = $("#desc").val();
                $.ajax({
                    url: "/Blog/AddComment",
                    data: { NickName: nickname, captcha: captcha, Contents: desc, PostsId: PostsId },
                    type: "Post",
                    dataType: "json",
                    success: function (data) {

                        layer.msg(data.message);
                        document.getElementById("codeimg").src = "/Comments/GetSubmitCode?r=" + Math.random();

                    },
                    error: function (data) {

                        layer.msg(data.message);
                    }
                });
            });
        })
    </script>
}
